package com.yanqu.road.server.cmd.activity.xingyoushanshui;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.XingYouShanShuiProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.xingyou.CrossXingYouActivity;
import com.yanqu.road.server.manager.activity.xingyou.CrossXingYouShanShuiMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C_XING_YOU_SHAN_SHUI_USE_ITEM, desc = "使用活动道具(建筑)")
public class CrossShanShuiUseItemCmd extends CrossUnionCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        XingYouShanShuiProto.ShanShuiUseItemReq req = XingYouShanShuiProto.ShanShuiUseItemReq.parseFrom(packet.getBytes());
        int activityId = req.getActivityId();
        CrossXingYouActivity activity = CrossXingYouShanShuiMgr.getActivity(activityId, groupId);
        if(activity != null){
            int itemId = 0;
            int num = 1;
            if(req.hasUserProp()) {
                itemId = req.getUserProp();
                if (req.hasUserPropNum()) {
                    num = req.getUserPropNum();
                }
            }
            int lv = 0;
            if(req.hasCurLv()){
                lv = req.getCurLv();
            }
            ret = activity.buildingUp(serverId, packet.getPlayerId(), req.getPosition(), itemId, num, lv);
            if(ret != 0){
                MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_XING_YOU_SHAN_SHUI_USE_ITEM, XingYouShanShuiProto.ShanShuiUseItemRsp.newBuilder().setRet(ret)));
            }
        }
    }

    @Override
    public void sendData() {

    }
}
